package com.phoenix.es.service;

import com.phoenix.es.pojo.Product;
import com.phoenix.es.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductSearchService {

    @Autowired
    private ProductRepository productRepository;

    public void save(Product product) {
        productRepository.save(product);
    }

    public List<Product> search(String keyword) {
        return productRepository.searchByNameCustom(keyword);
    }

    public List<Product> findAll(){
        List<Product> result = new ArrayList<Product>();
        productRepository.findAll().forEach(e -> result.add(e));
        return result;
    }


}
